<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use App\Http\Model\Categroy;

/**
 * Class CategoryController Ç°Ì¨ÉÌÆ·À¸Ä¿¿ØÖÆÆ÷
 * @package App\Http\Controllers\home
 */
class CategoryController extends Controller
{
    /**
     * ¼ÓÔØÀ¸Ä¿ÊÓÍ¼
     * @param int $cid À¸Ä¿id
     */
    public function index($cid){
    	//查找栏目id对应的商品
    	$goods = DB::table('goods')->where('cat_id',$cid)->orderBy('goods_id','desc')->paginate(2);
    	//取出热门推荐
    	$best = DB::table('goods')->where('is_best',1)->orderBy('goods_id','desc')->take(4)->get();
    	//取出浏览历史
    	$his = session('his')?session('his'):array();
    	if(!empty($his)){
    		foreach($his as $k=>$v){
    			$his[$k] = DB::table('goods')->where('goods_id',$v)->first();
    		}
    	}
        return view('home.category.category',['goods'=>$goods,'best'=>$best,'his'=>array_reverse($his)]);
    }

    //按照销量排序
    /*public function saleOrder($cid){
    	$goods = DB::table('goods')->where('cat_id',$cid)->orderBy('')->get();
        return view('home.category.category',['goods'=>$goods]);
    }*/

    //按照人气排序

    //按照价格排序
}
